package com.unione.map.view.adapter

import android.widget.CheckBox
import com.chad.library.adapter.base.BaseQuickAdapter
import com.chad.library.adapter.base.viewholder.BaseViewHolder
import com.unione.map.R
import com.unione.unione_protocol.robot_auto.bean.MapInfo

class MapListAdapter : BaseQuickAdapter<MapInfo, BaseViewHolder>(R.layout.layout_item_map) {

    private var mListener: OnMapCheckedListener? = null


    init {
        addChildClickViewIds(R.id.ivDelete)
    }

    fun setOnMapCheckedListener(listener: OnMapCheckedListener) {
        this.mListener = listener
    }


    override fun convert(holder: BaseViewHolder, item: MapInfo) {
        holder.setText(R.id.tvIndex, holder.absoluteAdapterPosition.toString())
        holder.setText(R.id.tvMapName, item.scene)
        holder.setText(R.id.tvCreateTime, item.createTime)
        holder.getView<CheckBox>(R.id.checkbox).isChecked=item.isChecked
        holder.getView<CheckBox>(R.id.checkbox)
            .setOnCheckedChangeListener { buttonView, isChecked ->
                if (mListener != null) {
                    mListener?.onChecked(isChecked, holder.absoluteAdapterPosition)
                }
            }
    }


    interface OnMapCheckedListener {
        fun onChecked(isChecked: Boolean, position: Int)
    }


}